Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate correct output on NumCPU() when using cgroups2 #9816

Merged
merged 34 commits into from
Aug 12, 2024

Conversation

nickorlow
Copy link
Contributor

@nickorlow nickorlow commented Mar 31, 2023

Updates the NumCPU() function in pkg/util/runtime/cpu_linux.go to work with cgroups2.

What this PR does / why we need it:

Change is required for proper functionality with cgroups2.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • CVE Report (Scanner found CVE and adding report)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation only

Which issue/s this PR fixes

Fixes #9665

How Has This Been Tested?

Generated example files that were within the [cgroups2 spec](https://docs.kernel.org/admin-guide/cgroup-v2.html and
tested our code to ensure it returned the correct outputs for each case.

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I've read the CONTRIBUTION guide
  • I have added unit and/or e2e tests to cover my changes.
  • All new and existing tests passed.
  • Added Release Notes.

Does my pull request need a release note?

Added support for detecting CPU count properly when using cgroups2

@k8s-ci-robot k8s-ci-robot added the needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. label Mar 31, 2023
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Mar 31, 2023

CLA Signed

The committers listed above are authorized under a signed CLA.

@k8s-ci-robot
Copy link
Contributor

Welcome @nickorlow!

It looks like this is your first PR to kubernetes/ingress-nginx 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes/ingress-nginx has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot
Copy link
Contributor

Hi @nickorlow. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. needs-kind Indicates a PR lacks a `kind/foo` label and requires one. needs-priority cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Mar 31, 2023
@longwuyuan
Copy link
Contributor

Hi @nickorlow ,

Thanks for this.

Please explore contributing tests for this.
Particularly e2e tests.

regards

@longwuyuan
Copy link
Contributor

/triage accepted
/kind bug

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. kind/bug Categorizes issue or PR as related to a bug. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-kind Indicates a PR lacks a `kind/foo` label and requires one. labels Mar 31, 2023
@nickorlow
Copy link
Contributor Author

nickorlow commented Mar 31, 2023

Hi @nickorlow ,

Thanks for this.

Please explore contributing tests for this. Particularly e2e tests.

regards

Should we include the tests in this PR or make a separate one?

@longwuyuan
Copy link
Contributor

I think that the change and the e2e-test in this PR will help feedback. thanks

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 16, 2023
@k8s-ci-robot k8s-ci-robot removed the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Apr 16, 2023
@tao12345666333
Copy link
Member

Thank you for your contribution

@LeMyst
Copy link
Contributor

LeMyst commented Sep 12, 2023

LGTM for the moment

Copy link
Contributor

@LeMyst LeMyst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything seems to be cgroup2 Unified Mode compatible and cgroup1.
Otherwise it fallback to no limit.
LGTM

Comment on lines 85 to 89
file.WriteString("4 2")
file.Sync()

assert.Equal(ginkgo.GinkgoT(), runtime.GetCgroupVersion(), int64(2))
assert.Equal(ginkgo.GinkgoT(), runtime.NumCPU(), 2)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you set a more complex and more realistic test, for cgroups v1 and v2.
Something like "50000 100000" to get a NumCPU at 0,5 ?

@runephilosof-karnovgroup
Copy link

runephilosof-karnovgroup commented Dec 6, 2023

@nickorlow @tao12345666333 Looks like this is stalled/forgotten?

@nickorlow
Copy link
Contributor Author

@nickorlow @tao12345666333 Looks like this is stalled/forgotten?

I think so.. anything more I need to do to have this merged? I believe all requested changes have been made

@LeMyst
Copy link
Contributor

LeMyst commented Feb 19, 2024

Any news?

Copy link

netlify bot commented Feb 21, 2024

Deploy Preview for kubernetes-ingress-nginx canceled.

Name Link
🔨 Latest commit e9f3717
🔍 Latest deploy log https://app.netlify.com/sites/kubernetes-ingress-nginx/deploys/664b5add62526c000838b40f

@scenusa-bd
Copy link

Any plans to have this merged? Thanks!

@tao12345666333
Copy link
Member

@nickorlow Sorry for the long long delay, could you please resolve the conflicts and make a rebase?
Then we can move forward, thank you!

@divigarg
Copy link

@nickorlow , can we get this through, please? thank you :)

@nickorlow
Copy link
Contributor Author

@tao12345666333 Everything updated. Had to make some changes to the tests since docker mounts the cgroup directory as ro unless you run it in privileged mode.

@strongjz
Copy link
Member

strongjz commented Jul 1, 2024

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 1, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: LeMyst, nickorlow, strongjz

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 1, 2024
@strongjz
Copy link
Member

strongjz commented Jul 1, 2024

/cherry-pick release-1.11

@k8s-infra-cherrypick-robot
Copy link
Contributor

@strongjz: once the present PR merges, I will cherry-pick it on top of release-1.11 in a new PR and assign it to you.

In response to this:

/cherry-pick release-1.11

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@LeMyst
Copy link
Contributor

LeMyst commented Aug 1, 2024

Are there any updates on this topic? What is preventing the merge of this PR?

@strongjz strongjz merged commit 6c404a5 into kubernetes:main Aug 12, 2024
26 of 27 checks passed
@k8s-infra-cherrypick-robot
Copy link
Contributor

@strongjz: #9816 failed to apply on top of branch "release-1.11":

Applying: file parsing for Cgroup2
Applying: added version detecting
Applying: ran gofmt
Applying: declarations to assignments
Applying: correct types
Applying: added test boilerplate
Using index info to reconstruct a base tree...
M	test/e2e/e2e.go
Falling back to patching base and 3-way merge...
Auto-merging test/e2e/e2e.go
CONFLICT (content): Merge conflict in test/e2e/e2e.go
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0006 added test boilerplate
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".

In response to this:

/cherry-pick release-1.11

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. kind/bug Categorizes issue or PR as related to a bug. lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. needs-priority size/L Denotes a PR that changes 100-499 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

func NumCPU() fails to return correct cpus when using cgroups2